package com.dl.study.module.user.controller;

import com.dl.study.base.config.redis.RedisUtil;
import com.dl.study.module.swagger.SwaggerTagConst;
import com.dl.study.module.user.domain.dto.UserDto;
import com.dl.study.module.user.domain.dto.UserQueryListDto;
import com.dl.study.module.user.service.UserService;
import com.dl.study.util.resp.ResponseDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: user
 * @Date: 2021/8/30 16:27
 * @Description:
 */
@RestController
@Api(value = "用户控制类", tags = SwaggerTagConst.User.USER_MANAGE_CONFIG, description = "用户模型控制类描述")
public class UserController {

    @Resource
    private RedisUtil redisUtil;
    @Value("${server.port}")
    private String serverPort;

    @Autowired
    private UserService userService;

    @GetMapping("/get/{id}")
    public String products(@PathVariable("id") Integer id) {
        return "调用商品服务返回：" + id + ",当前提供服务的端口为：" + serverPort;
    }


    @PostMapping("/user/add/")
    @ApiOperation("添加")
    public ResponseDTO<Object> add(@RequestBody UserQueryListDto userQueryListDto) {
        return userService.add(userQueryListDto);
    }

    @GetMapping("/redis/set")
    public String redisSetController(@RequestParam(value = "name") String name) {
        redisUtil.set("name", name);
        return "success";
    }

    @GetMapping("/redis/get")
    public String redisGetController(@RequestParam(value = "name") String name) {
        String names = (String) redisUtil.get("name");
        return names;
    }


    @PostMapping("/user/add1/")
    @ApiOperation("添加(策略模式)")
    public ResponseDTO<Object> add1(@RequestBody UserDto userDto) {
        return userService.orderHandler(userDto);
    }


}
